﻿using System;
using System.CodeDom.Compiler;
using System.Text;

namespace RuntimeCompiler
{
    public class CompilerException : Exception
    {
        public CompilerException( string message )
            : base( message ) { }

        public CompilerException( CompilerErrorCollection errors )
            : base( BuildErrorMessage( errors ) ) { }

        private static string BuildErrorMessage( CompilerErrorCollection errors )
        {
            StringBuilder sb = new StringBuilder( "Compiler Errors :" );

            foreach( CompilerError error in errors )
                sb.AppendFormat( "Line {0},{1}\t: {2}\n", error.Line, error.Column, error.ErrorText );

            return sb.ToString();
        }
    }
}
